﻿using System;
using System.Windows.Forms;
using Settings = OMC.Properties.Settings;
using Manager = OMC.DataManagement.Manager;
using StringResources = OMC.Properties.StringResources;
using System.Resources;

namespace OMC.UserInterface
{
    /// <summary>
    /// MyForm is a form to display options. the options form could be use to
    /// customize the Add-In "Outlook Mail Classifier".
    /// </summary>
    partial class MyForm : Form
    {
        Manager manager;
        /// <summary>
        /// The constructor to create a new object of MyForm, it needs a Manager Object
        /// </summary>
        public MyForm(Manager manager)
        {
            this.manager = manager;
            InitializeComponent();
            ResourceManager rm = StringResources.ResourceManager;

            //Set Resources
            groupBoxPreprocess.Text = rm.GetString("groupBoxPreprocess");
            groupBoxClassification.Text = rm.GetString("groupBoxClassification");
            labelOfPreprocessor.Text = rm.GetString("labelOfPreprocessor");
            checkBoxUseStopwords.Text = rm.GetString("checkBoxUseStopwords");
            comboBoxClassifier.Text = rm.GetString("comboBoxClassifier");
            comboBoxClassifier.DropDownStyle = ComboBoxStyle.DropDownList;
            comboBoxClassifier.Items.Add("NaiveBayesMultinomialUpdateable");
            comboBoxClassifier.Items.Add("NaiveBayesMultinomial");
            comboBoxClassifier.Items.Add("ComplementNaiveBayes");
            comboBoxClassifier.Items.Add("DMNBText");
            buttonSave.Text = rm.GetString("buttonSave");
            this.Text = rm.GetString("optionsTitle");
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        /// <summary>
        /// The Method set the state of the checkBox to the settings.
        /// </summary>
        /// <param name="sender">the sender object</param>
        /// <param name="e">The EventArgs object</param>
        private void checkBoxUseStopWords_CheckedChanged(object sender, EventArgs e)
        {
            Settings.Default.luceneAnalyzer = checkBoxUseStopwords.Checked;
        }

        /// <summary>
        /// The Method set the choosen classifier to the settings.
        /// </summary>
        /// <param name="sender">the sender object</param>
        /// <param name="e">The EventArgs object</param>
        private void comboBoxClassifier_SelectedIndexChanged(object sender, EventArgs e)
        {
            Settings.Default.classifierIndex = comboBoxClassifier.SelectedIndex;
        }

        /// <summary>
        /// The Method handle the click of the button.
        /// </summary>
        /// <param name="sender">the sender object</param>
        /// <param name="e">The EventArgs object</param>
        private void buttonOk_Click(object sender, EventArgs e)
        {
            //save the settings 
            Settings.Default.Save();
            manager.LoadCustomProperties();
            this.Close();
        }

        /// <summary>
        /// The Method get the settings and commit them to the form settings.
        /// </summary>
        /// <param name="sender">the sender object</param>
        /// <param name="e">The EventArgs object</param>
        private void MyForm_Load(object sender, EventArgs e)
        {
            checkBoxUseStopwords.Checked = Settings.Default.luceneAnalyzer;
            comboBoxClassifier.SelectedIndex = Settings.Default.classifierIndex;
        }
    }
}